<template>
  <view class="detail-container">
    <!-- 标题 -->
    <view class="detail-title-area">
      <text class="section-title" v-if="detailData.Title">
        {{ detailData.Title }}
      </text>
      <view class="meta-info">
        <text class="category-tag">{{ detailData.Category }}</text>
        <text class="create-time">{{ detailData.CreateTime }}</text>
      </view>
    </view>

    <!-- 封面图片 -->
    <image
      class="cover-image"
      :src="detailData.CoverImage"
      mode="aspectFill"
    ></image>

    <!-- 内容部分 -->
    <view class="content-section">
      <text class="section-text">{{ detailData.Content }}</text>
    </view>
  </view>
</template>

<script lang="ts">
import dayjs from 'dayjs'
import { Vue, Component } from 'vue-property-decorator'

@Component
export default class KnowledgeDetail extends Vue {
  categories: any = {
    1: '人脸识别',
    2: '安全认证',
    3: '数据加密',
    4: '网络防护'
  }
  // 详情数据
  get detailData() {
    const data = uni.getStorageSync('knowledgeDetail')
    return data
      ? {
          ...data,
          CreateTime: dayjs(data.CreateTime).format('YYYY-MM-DD HH:mm:ss'),
          Category: this.categories[data.Category]
        }
      : {}
  }
}
</script>

<style lang="scss" scoped>
.detail-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #f9f9f9;
  padding: 20rpx;
  padding-bottom: 30rpx;
}

.detail-header {
  display: flex;
  align-items: center;
  padding: 20rpx 30rpx;
  background-color: #1976d2;
  color: white;
  position: relative;

  .back-button {
    display: flex;
    align-items: center;
    font-size: 28rpx;

    .icon {
      margin-right: 10rpx;
      font-size: 36rpx;
    }
  }

  .detail-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 32rpx;
    font-weight: bold;
  }
}

.detail-content {
  flex: 1;
  padding: 30rpx;
}

.detail-title-area {
  margin-bottom: 40rpx;

  .main-title {
    display: block;
    font-size: 44rpx;
    font-weight: bold;
    margin-bottom: 20rpx;
    color: #333;
  }

  .meta-info {
    display: flex;
    align-items: center;

    .category-tag {
      padding: 6rpx 16rpx;
      background-color: #1976d2;
      color: white;
      border-radius: 8rpx;
      font-size: 24rpx;
      margin-right: 20rpx;
    }

    .create-time {
      font-size: 24rpx;
      color: #999;
    }
  }
}

.cover-image {
  width: 100%;
  border-radius: 16rpx;
  margin-bottom: 40rpx;
  height: 200rpx;
}

.section-title {
  display: block;
  font-size: 36rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
  color: #1976d2;
}
.content-section {
  margin-bottom: 50rpx;

  .section-text {
    display: block;
    font-size: 30rpx;
    line-height: 1.6;
    color: #333;
    margin-bottom: 30rpx;
    white-space: pre-line;
  }

  .section-image {
    width: 100%;
    border-radius: 12rpx;
    margin-top: 20rpx;
  }
}

.related-section {
  margin-top: 60rpx;
  border-top: 1px solid #eee;
  padding-top: 30rpx;

  .section-title {
    display: block;
    font-size: 36rpx;
    font-weight: bold;
    margin-bottom: 30rpx;
    color: #333;
  }

  .related-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24rpx;
  }

  .related-item {
    background-color: white;
    border-radius: 12rpx;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);

    .related-image {
      width: 100%;
      height: 200rpx;
    }

    .related-title {
      display: block;
      padding: 16rpx;
      font-size: 26rpx;
      color: #333;
    }
  }
}
</style>
